#include "hplcpumpbasiccontrolpage.h"
#include "modulemanager.h"
#include "modulehplcpump.h"
#include "modulehplcpumpparamiddefine.h"
#include "modulehplccmdid.h"
#include <QDebug>
#include <QCloseEvent>
#include <QGroupBox>

HplcPumpBasicControlPage::HplcPumpBasicControlPage(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle(tr("Hplc Pump Basic Control Page"));
    setAttribute(Qt::WA_DeleteOnClose);

    ModuleHplcPump *mod = static_cast<ModuleHplcPump*>(moduleManager->find(ModuleID_HPLC_PumpA));
    if (mod == nullptr)
        return;
    qDebug() << mod->getName();
    connect(mod, &ModuleHplcPump::parseCompleted,
            this, &HplcPumpBasicControlPage::onParseCompleted, Qt::QueuedConnection);

    // 流速
    m_lbFlow = new QLabel(tr("Flow"));
    m_leFlow = new QLineEdit();
    m_pbSetFlow = new QPushButton(tr("Set"));
    connect(m_pbSetFlow, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leFlow->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetFlow, var);
    });
    m_pbGetFlow = new QPushButton(tr("Get"));
    connect(m_pbGetFlow, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetFlow, var);
    });
    hblFlow = new QHBoxLayout();
    hblFlow->addWidget(m_lbFlow);
    hblFlow->addWidget(m_leFlow);
    hblFlow->addWidget(m_pbSetFlow);
    hblFlow->addWidget(m_pbGetFlow);

    // 流速百分比
    m_lbFlowPercent = new QLabel(tr("FlowPercent"));
    m_leFlowPercent = new QLineEdit();
    m_pbSetFlowPercent = new QPushButton(tr("Set"));
    connect(m_pbSetFlowPercent, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leFlowPercent->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetFlowPercent, var);
    });
    m_pbGetFlowPercent = new QPushButton(tr("Get"));
    connect(m_pbGetFlowPercent, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetFlowPercent, var);
    });
    hblFlowPercent = new QHBoxLayout();
    hblFlowPercent->addWidget(m_lbFlowPercent);
    hblFlowPercent->addWidget(m_leFlowPercent);
    hblFlowPercent->addWidget(m_pbSetFlowPercent);
    hblFlowPercent->addWidget(m_pbGetFlowPercent);

    // 最小压力
    m_lbPressureMin = new QLabel(tr("PressureMin"));
    m_lePressureMin = new QLineEdit();
    m_pbSetPressureMin = new QPushButton(tr("Set"));
    connect(m_pbSetPressureMin, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressureMin->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressureMin, var);
    });
    m_pbGetPressureMin = new QPushButton(tr("Get"));
    connect(m_pbGetPressureMin, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressureMin, var);
    });
    hblPressureMin = new QHBoxLayout();
    hblPressureMin->addWidget(m_lbPressureMin);
    hblPressureMin->addWidget(m_lePressureMin);
    hblPressureMin->addWidget(m_pbSetPressureMin);
    hblPressureMin->addWidget(m_pbGetPressureMin);

    // 最大压力
    m_lbPressureMax = new QLabel(tr("PressureMax"));
    m_lePressureMax = new QLineEdit();
    m_pbSetPressureMax = new QPushButton(tr("Set"));
    connect(m_pbSetPressureMax, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressureMax->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressureMax, var);
    });
    m_pbGetPressureMax = new QPushButton(tr("Get"));
    connect(m_pbGetPressureMax, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressureMax, var);
    });
    hblPressureMax = new QHBoxLayout();
    hblPressureMax->addWidget(m_lbPressureMax);
    hblPressureMax->addWidget(m_lePressureMax);
    hblPressureMax->addWidget(m_pbSetPressureMax);
    hblPressureMax->addWidget(m_pbGetPressureMax);

    // 预警压力
    m_lbPressureWarning = new QLabel(tr("PressureWarning"));
    m_lePressureWarning = new QLineEdit();
    m_pbSetPressureWarning = new QPushButton(tr("Set"));
    connect(m_pbSetPressureWarning, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressureWarning->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressureWarning, var);
    });
    m_pbGetPressureWarning = new QPushButton(tr("Get"));
    connect(m_pbGetPressureWarning, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressureWarning, var);
    });
    hblPressureWarning = new QHBoxLayout();
    hblPressureWarning->addWidget(m_lbPressureWarning);
    hblPressureWarning->addWidget(m_lePressureWarning);
    hblPressureWarning->addWidget(m_pbSetPressureWarning);
    hblPressureWarning->addWidget(m_pbGetPressureWarning);

    // 启动/停止
    m_lbStartStop = new QLabel(tr("StartStop"));
    m_leStartStop = new QLineEdit();
    m_pbSetStartStop = new QPushButton(tr("Set"));
    connect(m_pbSetStartStop, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leStartStop->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetStartStop, var);
    });
    m_pbGetStartStop = new QPushButton(tr("Get"));
    connect(m_pbGetStartStop, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetStartStop, var);
    });
    hblStartStop = new QHBoxLayout();
    hblStartStop->addWidget(m_lbStartStop);
    hblStartStop->addWidget(m_leStartStop);
    hblStartStop->addWidget(m_pbSetStartStop);
    hblStartStop->addWidget(m_pbGetStartStop);

    // 暂停/恢复
    m_lbPauseRestore = new QLabel(tr("PauseRestore"));
    m_lePauseRestore = new QLineEdit();
    m_pbSetPauseRestore = new QPushButton(tr("Set"));
    connect(m_pbSetPauseRestore, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePauseRestore->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPauseRestore, var);
    });
    m_pbGetPauseRestore = new QPushButton(tr("Get"));
    connect(m_pbGetPauseRestore, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPauseRestore, var);
    });
    hblPauseRestore = new QHBoxLayout();
    hblPauseRestore->addWidget(m_lbPauseRestore);
    hblPauseRestore->addWidget(m_lePauseRestore);
    hblPauseRestore->addWidget(m_pbSetPauseRestore);
    hblPauseRestore->addWidget(m_pbGetPauseRestore);

    // 清洗
    m_lbPurge = new QLabel(tr("Purge"));
    m_lePurge = new QLineEdit();
    m_pbSetPurge = new QPushButton(tr("Set"));
    connect(m_pbSetPurge, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePurge->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPurge, var);
    });
    m_pbGetPurge = new QPushButton(tr("Get"));
    connect(m_pbGetPurge, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPurge, var);
    });
    hblPurge = new QHBoxLayout();
    hblPurge->addWidget(m_lbPurge);
    hblPurge->addWidget(m_lePurge);
    hblPurge->addWidget(m_pbSetPurge);
    hblPurge->addWidget(m_pbGetPurge);

    // 清洗流速
    m_lbPurgeFlow = new QLabel(tr("PurgeFlow"));
    m_lePurgeFlow = new QLineEdit();
    m_pbSetPurgeFlow = new QPushButton(tr("Set"));
    connect(m_pbSetPurgeFlow, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePurgeFlow->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPurgeFlow, var);
    });
    m_pbGetPurgeFlow = new QPushButton(tr("Get"));
    connect(m_pbGetPurgeFlow, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPurgeFlow, var);
    });
    hblPurgeFlow = new QHBoxLayout();
    hblPurgeFlow->addWidget(m_lbPurgeFlow);
    hblPurgeFlow->addWidget(m_lePurgeFlow);
    hblPurgeFlow->addWidget(m_pbSetPurgeFlow);
    hblPurgeFlow->addWidget(m_pbGetPurgeFlow);

    // 清洗时间
    m_lbPurgeTime = new QLabel(tr("PurgeTime"));
    m_lePurgeTime = new QLineEdit();
    m_pbSetPurgeTime = new QPushButton(tr("Set"));
    connect(m_pbSetPurgeTime, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePurgeTime->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPurgeTime, var);
    });
    m_pbGetPurgeTime = new QPushButton(tr("Get"));
    connect(m_pbGetPurgeTime, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPurgeTime, var);
    });
    hblPurgeTime = new QHBoxLayout();
    hblPurgeTime->addWidget(m_lbPurgeTime);
    hblPurgeTime->addWidget(m_lePurgeTime);
    hblPurgeTime->addWidget(m_pbSetPurgeTime);
    hblPurgeTime->addWidget(m_pbGetPurgeTime);

    // 压力归零
    m_lbPressureClear = new QLabel(tr("PressureClear"));
    m_lePressureClear = new QLineEdit();
    m_pbSetPressureClear = new QPushButton(tr("Set"));
    connect(m_pbSetPressureClear, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressZero, var);
    });
    m_pbGetPressureClear = new QPushButton(tr("Get"));
    connect(m_pbGetPressureClear, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressZero, var);
    });
    hblPressureClear = new QHBoxLayout();
    hblPressureClear->addWidget(m_lbPressureClear);
    hblPressureClear->addWidget(m_lePressureClear);
    hblPressureClear->addWidget(m_pbSetPressureClear);
    hblPressureClear->addWidget(m_pbGetPressureClear);

    // 压力上传频率
    m_lbPressureUploadFreq = new QLabel(tr("PressureUploadFreq"));
    m_lePressureUploadFreq = new QLineEdit();
    m_pbSetPressureUploadFreq = new QPushButton(tr("Set"));
    connect(m_pbSetPressureUploadFreq, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressureUploadFreq->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressUploadFreq, var);
    });
    m_pbGetPressureUploadFreq = new QPushButton(tr("Get"));
    connect(m_pbGetPressureUploadFreq, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressUploadFreq, var);
    });
    hblPressureUploadFreq = new QHBoxLayout();
    hblPressureUploadFreq->addWidget(m_lbPressureUploadFreq);
    hblPressureUploadFreq->addWidget(m_lePressureUploadFreq);
    hblPressureUploadFreq->addWidget(m_pbSetPressureUploadFreq);
    hblPressureUploadFreq->addWidget(m_pbGetPressureUploadFreq);

    // 压力补偿
    m_lbPressureCompen = new QLabel(tr("PressureCompen"));
    m_lePressureCompen = new QLineEdit();
    m_pbSetPressureCompen = new QPushButton(tr("Set"));
    connect(m_pbSetPressureCompen, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressureCompen->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetFlowPressCompen, var);
    });
    m_pbGetPressureCompen = new QPushButton(tr("Get"));
    connect(m_pbGetPressureCompen, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetFlowPressCompen, var);
    });
    hblPressureCompen = new QHBoxLayout();
    hblPressureCompen->addWidget(m_lbPressureCompen);
    hblPressureCompen->addWidget(m_lePressureCompen);
    hblPressureCompen->addWidget(m_pbSetPressureCompen);
    hblPressureCompen->addWidget(m_pbGetPressureCompen);

    // 泵模式
    m_lbMode = new QLabel(tr("Mode"));
    m_leMode = new QLineEdit();
    m_pbSetMode = new QPushButton(tr("Set"));
    connect(m_pbSetMode, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leMode->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_SetMode, var);
    });
    m_pbGetMode = new QPushButton(tr("Get"));
    connect(m_pbGetMode, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetMode, var);
    });
    hblMode = new QHBoxLayout();
    hblMode->addWidget(m_lbMode);
    hblMode->addWidget(m_leMode);
    hblMode->addWidget(m_pbSetMode);
    hblMode->addWidget(m_pbGetMode);

    // 压力
    m_lbPressure = new QLabel(tr("Pressure"));
    m_lePressure = new QLineEdit();
    m_pbSetPressure = new QPushButton(tr("Set"));
    connect(m_pbSetPressure, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_lePressure->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetPressure, var);
    });
    m_pbGetPressure = new QPushButton(tr("Get"));
    connect(m_pbGetPressure, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetPressure, var);
    });
    hblPressure = new QHBoxLayout();
    hblPressure->addWidget(m_lbPressure);
    hblPressure->addWidget(m_lePressure);
    hblPressure->addWidget(m_pbSetPressure);
    hblPressure->addWidget(m_pbGetPressure);

    // 运行模式
    m_lbRunMode = new QLabel(tr("RunMode"));
    m_leRunMode = new QLineEdit();
    m_pbSetRunMode = new QPushButton(tr("Set"));
    connect(m_pbSetRunMode, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leRunMode->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_SetRunMode, var);
    });
    m_pbGetRunMode = new QPushButton(tr("Get"));
    connect(m_pbGetRunMode, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_GetRunMode, var);
    });
    hblRunMode = new QHBoxLayout();
    hblRunMode->addWidget(m_lbRunMode);
    hblRunMode->addWidget(m_leRunMode);
    hblRunMode->addWidget(m_pbSetRunMode);
    hblRunMode->addWidget(m_pbGetRunMode);

    // 恒压泵专用
    // 最大流速
    m_lbCP_FlowMax = new QLabel(tr("FlowMax"));
    m_leCP_FlowMax = new QLineEdit();
    m_pbSetCP_FlowMax = new QPushButton(tr("Set"));
    connect(m_pbSetCP_FlowMax, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leCP_FlowMax->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_FlowMax, var);
    });
    m_pbGetCP_FlowMax = new QPushButton(tr("Get"));
    connect(m_pbGetCP_FlowMax, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_FlowMax, var);
    });
    hblCP_FlowMax = new QHBoxLayout();
    hblCP_FlowMax->addWidget(m_lbCP_FlowMax);
    hblCP_FlowMax->addWidget(m_leCP_FlowMax);
    hblCP_FlowMax->addWidget(m_pbSetCP_FlowMax);
    hblCP_FlowMax->addWidget(m_pbGetCP_FlowMax);

    // 最小流速
    m_lbCP_FlowMin = new QLabel(tr("FlowMin"));
    m_leCP_FlowMin = new QLineEdit();
    m_pbSetCP_FlowMin = new QPushButton(tr("Set"));
    connect(m_pbSetCP_FlowMin, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leCP_FlowMin->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_FlowMin, var);
    });
    m_pbGetCP_FlowMin = new QPushButton(tr("Get"));
    connect(m_pbGetCP_FlowMin, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_FlowMin, var);
    });
    hblCP_FlowMin = new QHBoxLayout();
    hblCP_FlowMin->addWidget(m_lbCP_FlowMin);
    hblCP_FlowMin->addWidget(m_leCP_FlowMin);
    hblCP_FlowMin->addWidget(m_pbSetCP_FlowMin);
    hblCP_FlowMin->addWidget(m_pbGetCP_FlowMin);

    // 压力阈值
    m_lbCP_PressThreshold = new QLabel(tr("PressThreshold"));
    m_leCP_PressThreshold = new QLineEdit();
    m_pbSetCP_PressThreshold = new QPushButton(tr("Set"));
    connect(m_pbSetCP_PressThreshold, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leCP_PressThreshold->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_PressThreshold, var);
    });
    m_pbGetCP_PressThreshold = new QPushButton(tr("Get"));
    connect(m_pbGetCP_PressThreshold, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_PressThreshold, var);
    });
    hblCP_PressThreshold = new QHBoxLayout();
    hblCP_PressThreshold->addWidget(m_lbCP_PressThreshold);
    hblCP_PressThreshold->addWidget(m_leCP_PressThreshold);
    hblCP_PressThreshold->addWidget(m_pbSetCP_PressThreshold);
    hblCP_PressThreshold->addWidget(m_pbGetCP_PressThreshold);

    // 目标压力
    m_lbCP_Press = new QLabel(tr("Press"));
    m_leCP_Press = new QLineEdit();
    m_pbSetCP_Press = new QPushButton(tr("Set"));
    connect(m_pbSetCP_Press, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leCP_Press->text().toFloat());
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_Press, var);
    });
    m_pbGetCP_Press = new QPushButton(tr("Get"));
    connect(m_pbGetCP_Press, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_Press, var);
    });
    hblCP_Press = new QHBoxLayout();
    hblCP_Press->addWidget(m_lbCP_Press);
    hblCP_Press->addWidget(m_leCP_Press);
    hblCP_Press->addWidget(m_pbSetCP_Press);
    hblCP_Press->addWidget(m_pbGetCP_Press);

    // PID参数
    m_lbCP_PID = new QLabel(tr("PID"));
    m_leCP_PID_P = new QLineEdit();
    m_leCP_PID_I = new QLineEdit();
    m_leCP_PID_D = new QLineEdit();
    m_pbSetCP_PID = new QPushButton(tr("Set"));
    connect(m_pbSetCP_PID, &QPushButton::clicked, this, [=](){
        QVariant var;
        hplc::PID pid;
        pid.p = m_leCP_PID_P->text().toFloat();
        pid.i = m_leCP_PID_I->text().toFloat();
        pid.d = m_leCP_PID_D->text().toFloat();
        var.setValue(pid);
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_PID, var);
    });
    m_pbGetCP_PID = new QPushButton(tr("Get"));
    connect(m_pbGetCP_PID, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_PID, var);
    });
    hblCP_PID = new QHBoxLayout();
    hblCP_PID->addWidget(m_lbCP_PID);
    hblCP_PID->addWidget(m_leCP_PID_P);
    hblCP_PID->addWidget(m_leCP_PID_I);
    hblCP_PID->addWidget(m_leCP_PID_D);
    hblCP_PID->addWidget(m_pbSetCP_PID);
    hblCP_PID->addWidget(m_pbGetCP_PID);

    // 当前压力和pid输出
    m_lbCP_PressPidOut = new QLabel(tr("PressPidOut"));
    m_leCP_CurrentPress = new QLineEdit();
    m_leCP_PidOut = new QLineEdit();
    m_pbSetCP_PressPidOut = new QPushButton(tr("Set"));
    m_pbSetCP_PressPidOut->setEnabled(false);
    m_pbGetCP_PressPidOut = new QPushButton(tr("Get"));
    connect(m_pbGetCP_PressPidOut, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_PressPidOut, var);
    });
    hblCP_PressPidOut = new QHBoxLayout();
    hblCP_PressPidOut->addWidget(m_lbCP_PressPidOut);
    hblCP_PressPidOut->addWidget(m_leCP_CurrentPress);
    hblCP_PressPidOut->addWidget(m_leCP_PidOut);
    hblCP_PressPidOut->addWidget(m_pbSetCP_PressPidOut);
    hblCP_PressPidOut->addWidget(m_pbGetCP_PressPidOut);

    // 当前压力和pid输出的上传频率
    m_lbCP_PressPidOutUploadFreq = new QLabel(tr("PressPidOutUploadFreq"));
    m_leCP_PressPidOutUploadFreq = new QLineEdit();
    m_pbSetCP_PressPidOutUploadFreq = new QPushButton(tr("Set"));
    connect(m_pbSetCP_PressPidOutUploadFreq, &QPushButton::clicked, this, [=](){
        QVariant var;
        var.setValue(m_leCP_PressPidOutUploadFreq->text().toUInt());
        mod->setProtocolCmd(hplc::PumpCmdID_Set_CP_PressPidOutUploadFreq, var);
    });
    m_pbGetCP_PressPidOutUploadFreq = new QPushButton(tr("Get"));
    connect(m_pbGetCP_PressPidOutUploadFreq, &QPushButton::clicked, this, [=](){
        QVariant var;
        mod->getProtocolCmd(hplc::PumpCmdID_Get_CP_PressPidOutUploadFreq, var);
    });
    hblCP_PressPidOutUploadFreq = new QHBoxLayout();
    hblCP_PressPidOutUploadFreq->addWidget(m_lbCP_PressPidOutUploadFreq);
    hblCP_PressPidOutUploadFreq->addWidget(m_leCP_PressPidOutUploadFreq);
    hblCP_PressPidOutUploadFreq->addWidget(m_pbSetCP_PressPidOutUploadFreq);
    hblCP_PressPidOutUploadFreq->addWidget(m_pbGetCP_PressPidOutUploadFreq);

    QVBoxLayout *vblConstPressure = new QVBoxLayout();
    vblConstPressure->addLayout(hblCP_FlowMax);
    vblConstPressure->addLayout(hblCP_FlowMin);
    vblConstPressure->addLayout(hblCP_PressThreshold);
    vblConstPressure->addLayout(hblCP_Press);
    vblConstPressure->addLayout(hblCP_PID);
    vblConstPressure->addLayout(hblCP_PressPidOut);
    vblConstPressure->addLayout(hblCP_PressPidOutUploadFreq);

    QGroupBox *gbConstPressure = new QGroupBox();
    gbConstPressure->setTitle(tr("Const Pressure Run Mode"));
    gbConstPressure->setLayout(vblConstPressure);


    QVBoxLayout *vbl = new QVBoxLayout();
    vbl->addLayout(hblFlow);
    vbl->addLayout(hblFlowPercent);
    vbl->addLayout(hblPressureMin);
    vbl->addLayout(hblPressureMax);
    vbl->addLayout(hblPressureWarning);
    vbl->addLayout(hblStartStop);
    vbl->addLayout(hblPauseRestore);
    vbl->addLayout(hblPurge);
    vbl->addLayout(hblPurgeFlow);
    vbl->addLayout(hblPurgeTime);
    vbl->addLayout(hblPressureClear);
    vbl->addLayout(hblPressureUploadFreq);
    vbl->addLayout(hblPressureCompen);
    vbl->addLayout(hblMode);
    vbl->addLayout(hblPressure);
    vbl->addLayout(hblRunMode);
    vbl->addWidget(gbConstPressure);
    setLayout(vbl);
}

HplcPumpBasicControlPage::~HplcPumpBasicControlPage()
{

}

void HplcPumpBasicControlPage::closeEvent(QCloseEvent *event)
{
    disconnect();
    event->accept();
}

void HplcPumpBasicControlPage::onParseCompleted(int id, const QVariant &var)
{
    switch (id)
    {
        case hplc::PumpCmdID_SetFlow:
        {
            float flow = var.toFloat();
            m_leFlow->setText(QString::number(flow));
        }
        break;
        case hplc::PumpCmdID_SetFlowPercent:
        {
            quint8 percent = var.toUInt();
            m_leFlowPercent->setText(QString::number(percent));
        }
        break;
        case hplc::PumpCmdID_SetPressureMin:
        {
            float press = var.toFloat();
            m_lePressureMin->setText(QString::number(press));
        }
        break;
        case hplc::PumpCmdID_SetPressureMax:
        {
            float press = var.toFloat();
            m_lePressureMax->setText(QString::number(press));
        }
        break;
        case hplc::PumpCmdID_SetPressureWarning:
        {
            float press = var.toFloat();
            m_lePressureWarning->setText(QString::number(press));
        }
        break;
        case hplc::PumpCmdID_SetStartStop:
        {
            quint8 isStart = var.toUInt();
            m_leStartStop->setText(QString::number(isStart));
        }
        break;
        case hplc::PumpCmdID_SetPauseRestore:
        {
            quint8 isPause = var.toUInt();
            m_lePauseRestore->setText(QString::number(isPause));
        }
        break;
        case hplc::PumpCmdID_SetPurge:
        {
            quint8 isPurge = var.toUInt();
            m_lePurge->setText(QString::number(isPurge));
        }
        break;
        case hplc::PumpCmdID_SetPurgeFlow:
        {
            float flow = var.toFloat();
            m_lePurgeFlow->setText(QString::number(flow));
        }
        break;
        case hplc::PumpCmdID_SetPurgeTime:
        {
            quint8 time = var.toUInt();
            m_lePurgeTime->setText(QString::number(time));
        }
        break;
        case hplc::PumpCmdID_SetPressZero:
        {
            float voltage = var.toFloat();
            m_lePressureClear->setText(QString::number(voltage));
        }
        break;
        case hplc::PumpCmdID_SetPressUploadFreq:
        {
            quint8 freq = var.toUInt();
            m_lePressureUploadFreq->setText(QString::number(freq));
        }
        break;
        case hplc::PumpCmdID_SetFlowPressCompen:
        {
            quint8 isCompen = var.toUInt();
            m_lePressureCompen->setText(QString::number(isCompen));
        }
        break;
        case hplc::PumpCmdID_SetMode:
        {
            quint8 mode = var.toUInt();
            m_leMode->setText(QString::number(mode));
        }
        break;
        case hplc::PumpCmdID_SetPressure:
        {
            float pressure = var.toFloat();
            m_lePressure->setText(QString::number(pressure));
        }
        break;
        case hplc::PumpCmdID_SetRunMode:
        {
            quint8 mode = var.toUInt();
            m_leRunMode->setText(QString::number(mode));
        }
        break;

        // 恒压泵专用
        case hplc::PumpCmdID_Set_CP_FlowMax:
        {
            double flow = var.toFloat();
            m_leCP_FlowMax->setText(QString::number(flow));
        }
        break;
        case hplc::PumpCmdID_Set_CP_FlowMin:
        {
            double flow = var.toFloat();
            m_leCP_FlowMin->setText(QString::number(flow));
        }
        break;
        case hplc::PumpCmdID_Set_CP_PressThreshold:
        {
            double flow = var.toFloat();
            m_leCP_PressThreshold->setText(QString::number(flow));
        }
        break;
        case hplc::PumpCmdID_Set_CP_Press:
        {
            double pressure = var.toFloat();
            m_leCP_Press->setText(QString::number(pressure));
        }
        break;
        case hplc::PumpCmdID_Set_CP_PID:
        {
            hplc::PID pid = var.value<hplc::PID>();
            m_leCP_PID_P->setText(QString::number(pid.p));
            m_leCP_PID_I->setText(QString::number(pid.i));
            m_leCP_PID_D->setText(QString::number(pid.d));
        }
        break;
        case hplc::PumpCmdID_Set_CP_PressPidOut:
        {
            hplc::PressurePidOut current = var.value<hplc::PressurePidOut>();
            m_leCP_CurrentPress->setText(QString::number(current.pressure));
            m_leCP_PidOut->setText(QString::number(current.pidOut));
        }
        break;
        case hplc::PumpCmdID_Set_CP_PressPidOutUploadFreq:
        {
            quint8 freq = var.toUInt();
            m_leCP_PressPidOutUploadFreq->setText(QString::number(freq));
        }
        break;
        default:
        break;
    }
}
